package com.goods.controller.business;

import com.goods.business.service.IInStockService;
import com.goods.common.response.ResponseBean;
import com.goods.common.utils.JWTUtils;
import com.goods.common.vo.business.InStockDetailVO;
import com.goods.common.vo.business.InStockVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created with IntelliJ IDEA
 *
 * @Date: 2023/3/7 - 10:45
 * @Author: Hyoung
 * @Description:
 */
//9/business/inStock/findInStockList?pageNum=1&pageSize=10&status=0
@RestController
@RequestMapping("/business/inStock")
public class InStockController {


    @Autowired
    private IInStockService iInStockService;

    @GetMapping("/findInStockList")
    public ResponseBean findInStockList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                        @RequestParam(value = "pageSize") Integer pageSize,
                                        InStockVO inStockVO) {
        PageVO<InStockVO> pageVO = iInStockService.findInStockList(pageNum, pageSize, inStockVO);
        return ResponseBean.success(pageVO);
    }

    //?pageNum=1
    @GetMapping("/detail/{id}")
    public ResponseBean detailInStock(@PathVariable Integer id,
                                      @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {

        InStockDetailVO inStockDetailVO = iInStockService.detailInStock(id, pageNum);

        return ResponseBean.success(inStockDetailVO);
    }

    ///business/inStock/addIntoStock
    @PostMapping("/addIntoStock")
    public ResponseBean addIntoStock(@RequestBody InStockVO inStockVO, @RequestHeader("Authorization") String authorization) {
        String username = JWTUtils.getUsername(authorization);
        inStockVO.setOperator(username);
        iInStockService.addIntoStock(inStockVO);
        return ResponseBean.success();
    }

    @PutMapping("/remove/{id}")
    public ResponseBean removeInStock(@PathVariable Integer id) {
        iInStockService.remove(id);
        return ResponseBean.success();
    }

    @PutMapping("/back/{id}")
    public ResponseBean backInStock(@PathVariable Integer id) {
        iInStockService.back(id);
        return ResponseBean.success();
    }

    //publish
    @PutMapping("/publish/{id}")
    public ResponseBean publishInStock(@PathVariable Integer id) {
        iInStockService.publish(id);
        return ResponseBean.success();
    }

    @GetMapping("/delete/{id}")
    public ResponseBean deleteInStock(@PathVariable Integer id) {
        iInStockService.delete(id);
        return ResponseBean.success();
    }
}
